package cfca.paperless.client.servlet._2_extend._2_06_SynthesizeOuterSignature;

import java.util.Date;

import cfca.paperless.client.servlet.PaperlessClient;
import cfca.paperless.client.servlet.PaperlessConfig;
import cfca.paperless.client.util.GUID;
import cfca.paperless.client.util.IoUtil;
import cfca.paperless.client.util.PaperlessUtil;
import cfca.sadk.util.Base64;

public class SynthesizeOuterSignatureTest01 {

    /**
     * 自动化合成外部签名
     * 
     * @param args
     * @throws IOException
     * @throws
     */
    public static void main(String[] args) throws Exception {
        try {
            long timeStart = System.currentTimeMillis();// 开始时间
            // 初始化客户端对象
            PaperlessClient clientBean = new PaperlessClient(PaperlessConfig.extUrl, 10000, 60000);// 无纸化辅助接口的访问URL

            // 操作员编码或者机构号
            String operatorCode = PaperlessConfig.operatorCode;
            // 渠道编码，可以为空
            String channelCode = PaperlessConfig.channelCode;

            String sigString = "MIIFogYJKoZIhvcNAQcCoIIFkzCCBY8CAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCCA90wggPZMIICwaADAgECAgVQARAVQTANBgkqhkiG9w0BAQsFADBdMQswCQYDVQQGEwJDTjEwMC4GA1UECgwnQ2hpbmEgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MRwwGgYDVQQDDBNDRkNBIEFDUyBURVNUIE9DQTMyMB4XDTE3MDExMzAyNDU0NloXDTE3MDExMzEyNDU0NlowdzELMAkGA1UEBhMCQ04xEzARBgNVBAoMCkNGQ0EgT0NBMzIxDDAKBgNVBAsMA3N1YjEOMAwGA1UECwwFU2NlbmUxNTAzBgNVBAMMLDA1MUBjbGllbnRjZmNhLjExMTE0NDQ1QFpjZmNhMTExMjQ1NjkyMjIzQDM0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAg79CzdNgCsbf69F+fSKzBromTG1Pn7PuZXkKtr9VQJlFbjhfcWayk5bOXVZr6IsuwgxIMiHUJj/4k+0JFywMgLeI7WpwFMhGcI3CCGTJtnQ7nV00ydkm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l5/Fk8lhseTJg0l04U5frPRHPGzkm9gz5Jpp2NO+Dp2YPHXx4WnDFASVJ5Hw0Wza8Ezk59UKUVYSwVL5DO86egoZA6a5vHNVZp2Vfx95REi8G+QqwQUAR/OwWuyZBj1V4UD45KrW3mdhOxW9bW23koeTSbs3RqZWFzfDcXL1dUgm9NjZB6LHOGpoqXCTbYxXI+q4bcZnJHcm4d0wxnC/+nElj0I6dwcs0y7SurlT9Lv9Wdw0gQ114bQVTj1Sf";
            byte[] signature = Base64.decode(sigString);
            String id = "201803141721257297533992043166";
            String systemNo = GUID.generateId();//业务流水号 
            // 合成签名
            byte[] sealedPdfData = clientBean.synthesizeOuterSignature(systemNo,signature, id, operatorCode, channelCode);
            String errorRsString = PaperlessUtil.isError(sealedPdfData);

            if ("".equals(errorRsString)) {
                System.out.println("OK:synthesizeOuterSignature");
                System.out.println(sealedPdfData.length);
                IoUtil.write("./TestData/output/sealedPdf-synthesizeOuterSignature.pdf", sealedPdfData);
            } else {
                // 处理结果为异常，打印出错误码和错误信息
                System.out.println("NG:synthesizeOuterSignature");
                System.out.println(sealedPdfData.length);
                System.out.println(new String(sealedPdfData, "UTF-8"));
            }
            long timeEnd = System.currentTimeMillis();// 结束时间
            System.out.println("time:" + (timeEnd - timeStart));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
